<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #bird{
            width: 200px;
            height: 200px;
            position:fixed; /*固定定位，相对于浏览器所在的位置*/
            left: 100px;
            top: 100px;
        }
        #bird.left{transform: rotateY(0deg);}
        #bird.right{transform: rotateY(180deg);}
    </style>
</head>
<body>
    <img src="../images/bird.jpg" id="bird">
    <script>
        var bird = document.getElementById('bird')
        var speed = 10
        // 左上右下 37 38 39 40
        document.onkeydown = function(e){
            if(e.keyCode === 37) {
                var left = bird.offsetLeft // 获取鸟在水平的位置
                left -= speed //减去移动的值
                bird.style.left = left + 'px'
                bird.className = 'left'
            } else if(e.keyCode === 39) {
                var left = bird.offsetLeft // 获取鸟在水平的位置
                left += speed //加上移动的值
                bird.style.left = left + 'px'
                bird.className = 'right'
            }
            // offsetTop
        }
    </script>
</body>
</html>